package P044_SerializationCopy;

import org.junit.Test;

import java.io.Serializable;

/**
 * 推荐使用序列化实现对象拷贝
 *
 * @author xufy1
 */
public class ServializationCopy {

    /**
     * 网上对开源的 对象拷贝工具类比较
     * @see: https://blog.csdn.net/sunny243788557/article/details/106123933/
     */

    @Test
    public void test2() {
        Person f = new Person("父亲");
        Person s1 = new Person("大儿子", f);
        Person s2 = CloneUtils.clone(s1);
        s2.setName("小儿子");

        s1.getFather().setName("父亲父亲");

        System.out.println(s1.getName() + " 的父亲是 " + s1.getFather().getName());
        System.out.println(s2.getName() + " 的父亲是 " + s2.getFather().getName());
    }
}

class Person implements Serializable {

    private static final long serialVersionUID = 1L;
    private String name;
    private Person father;

    public Person(String _name) {
        name = _name;
    }

    public Person(String _name, Person _parent) {
        name = _name;
        father = _parent;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Person getFather() {
        return father;
    }

    public void setFather(Person father) {
        this.father = father;
    }

}
